import { Injectable } from '@angular/core';

// 服务
import { HttpService } from '../http/http.service';

// 模型
import { LoginRequest } from './login';


class Captchaid {
    public captchaid:string
    public msg:string
}
// Identifier: vnd.ant.auth.back+json; view=default
class AntAuthBack  {
	// 令牌
	public token:string
}

@Injectable()
export class LoginService {

    constructor(
        private httpService: HttpService
    ) { }

    // 登录
    login(username: string, password: string, captcha: string, captchaid: string): Promise<AntAuthBack> {
        let body = new LoginRequest(username, password, captcha, captchaid);
        return this.httpService.postJSON<AntAuthBack>('/auth/login_token', body);
    }

    // 获取验证码
    queryCaptcha(): Promise<Captchaid> {
        return this.httpService.getJSON<Captchaid>('/auth/captchaid', null);
    }

}
